import cv2
import os
import numpy as np
import matplotlib.pyplot as plt
video="./Resources/wrjs.mp4"
cap=cv2.VideoCapture(video)
frames=int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
print("帧数：",frames)
save_path="./Resources/wrjs/"
if not os.path.exists(save_path):
	os.makedirs(save_path)
cnt=1
for i in range(frames):
	retval,frame=cap.read()
	if retval:
		save_filename=os.path.join(save_path, "{:0>6d}.jpg".format(cnt))
		cv2.imwrite(save_filename,frame)
		cnt+=1
print("{}文件夹下共有{}个文件！".format(save_path,cnt-1))
plt.figure()
for i in range(4):
	n=np.random.randint(1,frames)
	img_path=os.path.join(save_path,"{:0>6d}.jpg".format(n))
	img=cv2.imread(img_path)
	plt.subplot(2,2,i+1)
	plt.imshow(img)
	plt.axis("off")
plt.show()
cap.release()